package 二维前缀和_二维差分_离散化技巧;

import java.io.*;

// 二维差分模版(洛谷)
// 测试链接 : https://www.luogu.com.cn/problem/P3397
// 请同学们务必参考如下代码中关于输入、输出的处理
// 这是输入输出处理效率很高的写法
// 提交以下的code，提交时请把类名改成"Main"，可以直接通过
public class Code03_DiffMatrixLuogu {

    public static int MAXN = 1005;

    public static int[][] diff = new int[MAXN][MAXN];

    public static int n, m;

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        while (in.nextToken() != StreamTokenizer.TT_EOF) {
            // 一个n * n 的二维数组
            n = (int) in.nval;
            in.nextToken();
            // 接下来读取m行 要进行两个坐标之间 差分的数据
            m = (int) in.nval;
            for (int i = 1, a, b, c, d; i <= m; i++) {
                in.nextToken();
                a = (int) in.nval;
                in.nextToken();
                b = (int) in.nval;
                in.nextToken();
                c = (int) in.nval;
                in.nextToken();
                d = (int) in.nval;
                // 进行差分操作
                add(a, b, c, d, 1);
            }
            // 进行 二维数组前缀和计算
            build();
            // 按要求进行输出
            for (int i = 1; i <= n; i++) {
                out.print(diff[i][1]);
                for (int j = 2; j <= n; j++) {
                    out.print(" " + diff[i][j]);
                }
                out.println();
            }
            clear();
        }
        out.flush();
        out.close();
        br.close();
    }

    public static void build() {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                diff[i][j] += diff[i][j - 1] + diff[i - 1][j] - diff[i - 1][j - 1];
            }
        }
    }

    public static void add(int a, int b, int c, int d, int v) {
        diff[a][b] += v;
        diff[c + 1][b] -= v;
        diff[a][d + 1] -= v;
        diff[c + 1][d + 1] += v;
    }

    public static void clear() {
        for (int i = 1; i <= n + 1; i++) {
            for (int j = 1; j <= n + 1; j++) {
                diff[i][j] = 0;
            }
        }
    }
}
